home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / DEMONSTR / ATEASY_2.ZIP / ATEZDLL.C < prev    next >
C/C++ Source or Header  |  1993-08-01  |  7KB  |  180 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM: ATEZDLL.c
  4.                           
  5.     BY     : Ronnie Yazma, Copyright 1993 GEOTEST Inc.   
  6.                           
  7.     PURPOSE: Demonstarte ATEasy type DLL functions
  8.     
  9.     TO COMPILE:
  10.              Use ATEZDLL.MAK when using Visual C/C++ v1.0 or MS-C 7.0
  11.              Use ATEZDLL.PRJ when using Borland C/C++ v3.1     
  12.              This file compiled in large memory model.
  13.     
  14.     VERSION: 2.00 (Jul-26-93)
  15.  
  16.     FUNCTIONS/SUBROUTINES:
  17.  
  18.          - MaxSub() : finds the max between 2 floats
  19.          - MaxLongFunc() : return the max between 2 floats
  20.          - AverageArray() : find the avarage of float array
  21.          - NoSpaces() : delete leading & trailing spaces in a string
  22.          - UCase2Dim() : convert 2 dim string to upper case
  23.          
  24. ****************************************************************************/
  25.  
  26. #include <windows.h>
  27. #include "ateasydl.h"   // contains ATEasy VAL, VAR parameters definitions 
  28. #include <string.h>     // for memmove 
  29. #include <ctype.h>      // for isspace, toupper
  30.  
  31. /****************************************************************************
  32.    FUNCTION: LibMain(HANDLE, WORD, WORD, LPSTR)
  33.  
  34.    PURPOSE:  Is called by LibEntry.  LibEntry is called by Windows when
  35.              the DLL is loaded.  The LibEntry routine is provided in
  36.              the LIBENTRY.OBJ in the SDK Link Libraries disk.  (The
  37.              source LIBENTRY.ASM is also provided.)
  38.  
  39.              LibEntry initializes the DLL's heap, if a HEAPSIZE value is
  40.              specified in the DLL's DEF file.  Then LibEntry calls
  41.              LibMain.  The LibMain function below satisfies that call.
  42.  
  43.              The LibMain function should perform additional initialization
  44.              tasks required by the DLL.  In this example, no initialization
  45.              tasks are required.  LibMain should return a value of 1 if
  46.              the initialization is successful.                 
  47.              
  48.              Some compilers vendors provides LibMain in their static libraries
  49.              so you're allowed not to include this function.
  50.  
  51. ****************************************************************************/
  52. int FAR PASCAL LibMain(HINSTANCE hInstance, WORD wDataSeg, WORD cbHeapSize, LPSTR lpszCmdLine)
  53. {
  54.     return(1);
  55. }
  56.  
  57.  
  58. /****************************************************************************
  59.  
  60.     FUNCTION: WEP(int)
  61.  
  62.     PURPOSE:  Performs cleanup tasks when the DLL is unloaded.  WEP() is
  63.               called automatically by Windows when the DLL is unloaded (no
  64.               remaining tasks still have the DLL loaded). Some compilers vendors
  65.               provides WEP in their static libraries so you're allowed not to
  66.               include this function (if you don't need cleanup). If you're 
  67.               using MS-C it is much safer to use _WEP instead of WEP               .
  68.               The WEP should return 1.
  69.               
  70. ****************************************************************************/
  71. int FAR PASCAL WEP(int nExitType)
  72. {
  73.     return(1);
  74. }
  75.  
  76. /****************************************************************************
  77.  
  78.     FUNCTION: MaxSub(hWnd, dX1, dX2, lpdResult)
  79.  
  80.     PURPOSE:  Finds the max of 2 floats (dX1 & dX2) into lpdResult.
  81.  
  82.        This subroutine defined in ATEasy as:
  83.        Max(fX1: VAL FLOAT, fX2: VAL FLOAT, fResult: VAR FLOAT): SUB DLL
  84.  
  85. ****************************************************************************/
  86. VOID _CALLBACK MaxSub(HWND hWnd, VAL_FLOAT dX1, VAL_FLOAT dX2, VAR_FLOAT lpdResult)
  87. {
  88.     *lpdResult=dX1 > dX2 ? dX1 : dX2;
  89. }
  90.  
  91. /****************************************************************************
  92.  
  93.     FUNCTION: MaxLongFunc(hWnd, lX1, lX2)
  94.  
  95.     PURPOSE:  Returns the max of 2 longs (lX1 & lX2).
  96.               Note that this is a function. 
  97.  
  98.        This function defined in ATEasy as:
  99.        Long Max(lX1: VAL LONG, lX2: VAL LONG): Function DLL
  100.  
  101. ****************************************************************************/
  102. long _CALLBACK MaxLongFunc(HWND hWnd, VAL_LONG lX1, VAL_LONG lX2)
  103. {
  104.     return lX1 > lX2 ? lX1 : lX2;
  105. }
  106.  
  107. /****************************************************************************
  108.  
  109.     FUNCTION: AverageArray(hWnd, vafNumbers, lpdResult)
  110.  
  111.     PURPOSE:  Calculate the mean value of vafNumbers array into lpdResult.
  112.  
  113.         This function defined in ATEasy as:
  114.         AverageArray(afNumbers : VAL FLOAT[], dResult : VAR FLOAT) : SUB DLL
  115.  
  116. ****************************************************************************/
  117. VOID _CALLBACK AverageArray(HWND hWnd, VAL_AFLOAT vafNumbers, VAR_FLOAT lpdResult)
  118. {
  119.     double      dResult=0.0;
  120.     short       i;
  121.  
  122.     for (i=0; i < vafNumbers->nDim2; i++)
  123.         dResult+=(vafNumbers->Ptr.lpFloat)[i];
  124.     if (vafNumbers->nDim2)
  125.         dResult/=vafNumbers->nDim2;
  126.     *lpdResult=dResult;
  127. }
  128.  
  129. /****************************************************************************
  130.  
  131.     FUNCTION: NoSpaces(hWnd, vsString)
  132.  
  133.     PURPOSE:  Delete leading & trailing spaces in a string
  134.  
  135.         This function defined in ATEasy as:
  136.         NoSpaces(s : VAR String)
  137.  
  138. ****************************************************************************/
  139. VOID _CALLBACK NoSpaces(HWND hWnd, VAR_ASTRING vsString)
  140. {
  141.     short       i, j;
  142.  
  143.     for (i=StrLen(vsString); i > 0; i--)            // delete trailing spaces 
  144.         if (!isspace(Str(vsString)[i-1])) break;
  145.     StrLen(vsString)=i;
  146.     for (j=0; j < i; j++)                           // delete leading spaces 
  147.         if (!isspace(Str(vsString)[j])) break;
  148.     if (j)                                          // move to start 
  149.     {   StrLen(vsString)-=j;
  150.         memmove(Str(vsString), &Str(vsString)[j], StrLen(vsString));
  151.     }
  152. }
  153.  
  154. /****************************************************************************
  155.  
  156.     FUNCTION: UCase2Dim(hWnd, vasStrings)
  157.  
  158.     PURPOSE:  convert 2 dim string to upper case
  159.  
  160.         This function defined in ATEasy as:
  161.         UCase2Dim(as : VAR String[,])
  162.  
  163. ****************************************************************************/
  164. VOID _CALLBACK UCase2Dim(HWND hWnd, VAR_ASTRING vasStrings)
  165. {
  166.     short       i, j, nLen;
  167.     LPSTR       lp;
  168.  
  169.     for (i=0; i < vasStrings->nDim1; i++)
  170.     {   lp=Str2D(vasStrings, i);                    // get the i string
  171.         nLen=Str2DLen(vasStrings, i);               // get the string length
  172.         for (j=0; j < nLen; j++)
  173.             lp[j]=toupper(lp[j]);                   // convert to upper case
  174.     }     
  175. }
  176.  
  177. /****************************************************************************
  178.                     E - O - F
  179. ****************************************************************************/
  180.